<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
</head>
<body class="pear-container">
<form class="layui-form" action="">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">

                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label" >项目ID</label>
                    <div class="layui-input-block">
                        <input id="proId" type="text" name="proId" lay-verify="id" class="layui-input">
                    </div>
                </div>

                <label class="layui-form-label">专家名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="searchText" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="role-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit=""
                    lay-filter="user-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</body>
</form>



<!--<script type="text/html" id="user-bar">-->

<!--    <button shiro:hasPermission="system:user:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="check"><i class="layui-icon layui-icon-layer"></i>-->
<!--    </button>-->

<!--</script>-->

<script type="text/html" id="role-enable">
    <input type="checkbox" name="enable" value="{{d.roleId}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="role-enable" {{d.enable== '0' ? 'checked' : '' }} >
</script>

<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let MODULE_PATH = rootPath+"/ExpertController";
        let cols = [
            [
                {type: 'checkbox'},
                {type: 'numbers'},
                {title: '姓名', field: 'nickname', align: 'center'},
                {title: '单位名称', field: 'depName', align: 'center'},
                {title: '专业职称', field: 'userTitle', align: 'center'},
                // {title: '学历', field: 'userEducation', align: 'center'},
                // {title: '学位', field: 'userAcademicDegree', align: 'center'},
                {title: '研究专长', field: 'userExpertise', align: 'center'},
                {title: '回避理由', field: 'other2', align: 'center',
                templet: function (data){
                    return '<input type="text" name="other2" lay-verify="other2" class="layui-input" value=" " />'
                }
                },

            ]
        ]

        //table表单列表
        table.render({
            elem: '#user-table',
            url: MODULE_PATH + '/list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
        });

        //table图标事件绑定
        table.on('tool(user-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }else if (obj.event === 'check') {
                window.check(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(user-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        // table.on('row(user-table))',function (obj){
        //
        // });

        //查询按钮绑定
        form.on('submit(role-query)', function (data) {
            table.reload('user-table', {where: data.field})
            return false;
        });



        //查看
        // window.check = function (obj) {
        //     layer.open({
        //         type: 2,
        //         title: '查看',
        //         shade: 0.1,
        //         area: ['500px', '500px'],
        //         content: MODULE_PATH + '/editCheck/' + obj.data['id']
        //     });
        // }


        //刷新按钮
        window.refresh = function () {
            table.reload('user-table');
        }

        //提交按钮绑定
        form.on('submit(user-update)', function (obj) {

            var proId = $("#proId").val();
            obj.field.projectId = proId;

            let dataIds = layui.table.checkStatus('user-table').data;
            if (dataIds.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }else if(dataIds.length >2){
                layer.msg("最多只能选择两名专家", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < dataIds.length; i++) {
                ids += dataIds[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            obj.field.expertIds = ids;

            let other2s = "";
            for (var i=0;i<$("table tbody tr").length;i++){
                var cur=$("table tbody tr:eq("+i+")").find("td:eq(0) div.layui-form-checked");
                if (cur.length==1){
                    var curcount=$("table tbody tr:eq("+i+")").find("td:last input").val();
                    other2s += curcount + ",";
                }
            }
            other2s = other2s.substr(0, other2s.length - 1);
            obj.field.other2s = other2s;

            $.ajax({
                url: MODULE_PATH+'/avoid',
                data: obj.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</html>